<?php
namespace app\front\middleware;
use app\front\logic\ApiLogic;
/**
 * @author KEL
 * @参数，加密验证 
 * @Date   2020-07-09 17:34:42
 * @Author  <1067547248@qq.com>
 */
class SignCheck{
	public function handle($request, \Closure $next){
        $lang = $request->header('lang');
        if(!$request->isPost()){
            return ApiLogic::return($lang, 100001);
        }
		$signTime = input('signTime',0);
        $signStr = input('signStr','');
        if(!$signTime){
        	return ApiLogic::return($lang, 101);
        }
        if(!$signStr){
        	return ApiLogic::return($lang, 102);
        }
        $cof = config('app');
        // print_r($cof);
        $sign_exp_time = $cof['sign_exp_time'];
        //时间验证
        if($sign_exp_time && (time()-$signTime>$sign_exp_time || $signTime-time()>$sign_exp_time)){
        	return ApiLogic::return($lang, 103);
        }

		$appid = $cof['tools_appid'];
		$secret	=	$cof['tools_secret'];

		$strs = $appid.$secret.$signTime;
		// echo MD5($strs);
		if($signStr!=MD5($strs)){
			return ApiLogic::return($lang, 100);
		}
		return $next($request);
    }


    public function end(\think\Response $response){
        // 回调行为
        // return $response;
    }
}